package com.bms.entity;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

/**
 * 角色
 * @author Lan
 */
@Entity
@Table(name = "T_ROLE")
@JsonIgnoreProperties (value = { "hibernateLazyInitializer", "userSet" })
public class Role extends BaseEntity{

	private static final long serialVersionUID = -4536991874185870049L;
	
	private String roleName;
	private String description;
	private Set<Privilege> privilegeSet;
	
	private Set<User> userSet;//多个用户对应一种角色
	
	public Role() {
	}

	public Role(String roleName) {
		this.roleName = roleName;
	}

	/**
	 * @author Lan
	 * @return 角色名称
	 */
	@Column(nullable = false, unique = true)
	public String getRoleName() {
		return roleName;
	}

	/**
	 * @author Lan
	 * @param roleName
	 *            角色名称
	 */
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	/**
	 * @author Lan
	 * @return 角色描述
	 */
	@Column(length = 200)
	public String getDescription() {
		return description;
	}

	/**
	 * @author Lan
	 * @param description
	 *            角色描述
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToMany //多对多关联 Role是主的一方 Privilege是附属的一方
	@JoinTable(name="T_ROLE_PRIVILEGE", //指定中间表表名
		joinColumns={@JoinColumn(name="roleID")},//本类主键在中间表生成的对应字段名
		inverseJoinColumns={@JoinColumn(name="privilegeID")}//对方类主键在中间表生成的对应字段名
	)
	public Set<Privilege> getPrivilegeSet() {
		return privilegeSet;
	}

	public void setPrivilegeSet(Set<Privilege> privilegeSet) {
		this.privilegeSet = privilegeSet;
	}

	//@OneToMany(mappedBy="role", fetch=FetchType.LAZY)
	@ManyToMany(mappedBy = "roleSet")
	public Set<User> getUserSet() {
		return userSet;
	}

	public void setUserSet(Set<User> userSet) {
		this.userSet = userSet;
	}

}
